﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sql_Dataprovider;
using System.Data;
using System.Data.SqlClient;

namespace DACK_N28_QLRCP
{
    public class RapChieu
    {
        private int _maRap;
        public int MaRap
        {
            get { return _maRap; }
            set { _maRap = value; }
        }
        private string _tenRap;
        public string TenRap
        {
            get { return _tenRap; }
            set { _tenRap = value; }
        }
        private string _diaChi;
        public string DiaChi
        {
            get { return _diaChi; }
            set { _diaChi = value; }
        }
    }
    class RapChieu_DAO
    {
        public static Boolean ThemRC(RapChieu rc)
        {
            Sql_DataProvider INS = new Sql_DataProvider();
            string sql = string.Format("Insert_RapChieu");
            SqlParameter[] pr = {new SqlParameter("@TenRap", rc.TenRap),
                                 new SqlParameter("@DiaChi", rc.DiaChi)};
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }
            return INS.SQL_ExecuteNonQuery(cmd);
        }
        public static Boolean SuaRC(RapChieu rcUpdate)
        {
            Sql_DataProvider UPD = new Sql_DataProvider();
            string sql = string.Format("Update_RapChieu");
            SqlParameter[] pr = {new SqlParameter("@MaRap", rcUpdate.MaRap),
                                 new SqlParameter("@TenRap", rcUpdate.TenRap),
                                 new SqlParameter("@DiaChi", rcUpdate.DiaChi)};
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }
            return UPD.SQL_ExecuteNonQuery(cmd);
        }
        public static Boolean XoaRC(int id)
        {
            Sql_DataProvider Remove = new Sql_DataProvider();
            string sql = string.Format("Remove_RapChieu");
            SqlParameter pr = new SqlParameter("@maRap", id);
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(pr);
            return Remove.SQL_ExecuteNonQuery(cmd);
        }
        public static RapChieu Get_Rap (int marap)
        {
            RapChieu rc = new RapChieu();
            Sql_DataProvider getRC = new Sql_DataProvider();
            string sql = "select * from Rap where MaRap =" + marap;
            SqlDataReader reader = getRC.SQL_ExcuteQueryReader(sql);
            if (reader.Read())
            {
                rc.MaRap = Convert.ToInt32(reader["MaRap"]);
                rc.TenRap = reader["TenRap"].ToString();
                rc.DiaChi = reader["DiaChi"].ToString();
            }
            getRC.Connect.Close();
            return rc;
        }
    }
}
